package com.heima.media.controller.v1;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: itheima
 * @create: 2022-05-13 12:11
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService wmChannelService;


    /**
     * 列表查询频道
     *
     * @return
     */
    @ApiOperation(value = "根据名称模糊查询分页列表", notes = "author:mcm")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "查询对象", required = true, dataType = "ChannelDto")
    @PostMapping("/list")
    public ResponseResult listByName(@RequestBody ChannelDto dto) {
        return wmChannelService.listByName(dto);
    }


    /**
     * 保存频道
     *
     * @param entity
     * @return
     */
    @PostMapping
    public ResponseResult saveChannel(@RequestBody WmChannel entity) {
        return wmChannelService.saveChannel(entity);
    }


    /**
     * 查询所有的频道
     *
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }

}
